<template>
  <div class="app-container">
    <el-container class="m-container infinite-list" style="border: 1px solid #eee" v-infinite-scroll="moreMerchantData">
      <el-aside width="150px" class="container-left" style="background-color: #ffffff">
        <el-menu
          default-active="0"
          class="el-menu-vertical-demo">
          <el-menu-item class="infinite-list-item" v-for="(item,index) in merchantList" :key="index" :index="index.toString()" @click="toDetail(item)">
            <div slot="title" class="merchant-name">
              {{item.name}}
            </div>
          </el-menu-item>
        </el-menu>
      </el-aside>

      <el-container>
        <el-main>
          <el-scrollbar style="height: 100%;">
            <all-merchant v-show="current==1"/>
            <store-one :merchant_id="merchant_id" v-show="current==2" />
          </el-scrollbar>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
  import all_merchant from "@/views/storeManage/children/store_one/all_merchant";
  import store_one from "@/views/storeManage/children/store_one/store_one";
  export default {
    components: {
      "all-merchant": all_merchant,
      "store-one": store_one
    },
    data() {
      return {
        merchantList: [],
        page: 1,
        limit: 99,
        total: 0,
        current: 1,
        merchant_id: ''
      }
    },
    watch: {

    },
    created() {

    },
    mounted() {
      this.getMerchantList()
    },
    methods: {

      moreMerchantData() {
        this.page = 1
        /*this.getMerchantList()*/
      },

      async getMerchantList() {
        let res = await this.$api.getMerchantList({
          page: this.page,
          limit: this.limit
        })
        if(res.data.level==="success"){
          this.merchantList = []
          this.merchantList.push({id: -1,name: '全部平台'})
          this.merchantList = this.merchantList.concat(res.data.data)
        }
      },

      toDetail(item) {
        /*if(item.id!=-1){
          this.$router.push({path:'/storeManage/store_list/store_one',query: {row: item.id,row2:item.name}})
        } else{
          this.$router.push({path:'/storeManage/store_list/all_merchant'})
        }*/
        if(item.id!=-1){
          this.current = 2
          this.merchant_id = item.id
        } else{
          this.current = 1
        }
      }

    }
  }
</script>
<style lang="scss" scoped="scoped">
  .app-container{
    background-color: #EDEDED;
    min-height: calc(100vh - 50px);
    padding: 8px;
    overflow: auto;
    .m-container{
      height: calc(100vh - 66px);
    }
    .container-left{
      height: calc(100vh - 66px);
      overflow: auto;
    }
    .container-right{
      height: calc(100vh - 66px);
      overflow: auto;
    }
    .store-container{
      display: flex;
      flex-direction: column;
      background-color: #ffffff;
      cursor: pointer;
      /*min-height: calc(100vh - 50px);*/
      .store-item{
        height: 60px;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
        padding: 0 5px;
      }


    }

    .merchant-name{
      display: flex;
      align-items: center;
      justify-content: center;
      height: 100%;
    }

  }
  .store-item :hover{
    color: #00a0e9;
    font-weight: bold;
  }
</style>

<style scoped>
  /deep/ .el-main{
    padding: 0 0 0 10px;
  }
  /deep/ .el-menu-item, .el-submenu__title{
    white-space: pre-wrap;
    line-height: 20px;
  }
  .el-scrollbar__wrap {
    overflow-x: hidden;
  }
</style>
